using CStock;
using System;
using NUnit.Framework;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;
using TestCases.UI.SettingsUI;

namespace TestCases.StockData
{
    /// <summary>Some simple Tests.</summary>
    /// 
    [TestFixture]
    public class ProgramContextTest : ProgramContext_TestCases
    {
        public IProgramContext ProgramContext
        {
            get
            {
                return this.programContext;
            }
        }


        [Test]
        public void CREATE_new_ProgramContext_And_SAVE()
        {
            ProgramFactory pf = new ProgramFactory();
            pf.Create_TestData();
            this.programContext = pf.ProgramContext;
            Save_ProgramContext();
        }


        /// <summary>
        /// 
        /// </summary>
        [Test]
        public void ConfigurationTest()
        {
            this.programContext.Logfile.WriteCurrentTime("ConfigurationTest");
            this.programContext.GetOrCreateConfiguration(false);
            IConfiguration config = this.programContext.Configuration;
            Assert.IsNotNull(config);
            Assert.IsTrue(programContext.Configuration.ResetPathFromConfiguration());
            double d = this.programContext.Logfile.GetTimeSpanMilliseconds("ConfigurationTest");
            Debug.WriteLine("TimeSpan for ConfigurationTest: " + d.ToString());
        }


        [Test]
        public void CreateNewProgramContext_Test()
        {
            string myID = "Test";
            string myPath = System.IO.Path.Combine(new string[] { AppDomain.CurrentDomain.BaseDirectory, "Data", myID });
            this.programContext = CStock.ProgramContext.CreateProgramContext(myPath, myID, false);
        }


        [Test]
        public void ProgramContext_OpenOrCreate_Last()
        {
            this.programContext = CStock.ProgramContext.CreateProgramContext(false);
            this.programContext.OpenLastSaved();
        }


        [Test]
        public void ProgramContext_OpenOrCreate_Default()
        {
            this.programContext = CStock.ProgramContext.CreateProgramContext(false);
            string myID = "Default";
            this.programContext.ProgramContext_OpenOrCreate(myID, false);
        }


        [Test]
        public void ProgramContext_OpenOrCreate_NewTest()
        {
            this.programContext = CStock.ProgramContext.CreateProgramContext(false);
            string myID = "NewTest";
            this.programContext.ProgramContext_OpenOrCreate(myID, false);
        }


        [Test]
        public void CreateAndSave_NewProgramContext()
        {
            string myPath = CStock.ProgramContext.PathBin;
            this.programContext.SetNewPath_ID(myPath, "test2");
            Save_ProgramContext();
        }


        private void Save_ProgramContext()
        {
            programContext.ResetPathFromConfiguration();
            Assert.IsTrue(programContext.Serialize());
        }
    }
}